home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 January / january_2001.iso / intercd / root / ^4Developers / VB / visbasdb / VBDB / VBDB Code / VB6 Code / Class 6 / Example6-7AD.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-09-17  |  10.0 KB  |  345 lines

  1. VERSION 5.00
  2. Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
  3. Begin VB.Form frmAuthors 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Authors"
  6.    ClientHeight    =   2625
  7.    ClientLeft      =   45
  8.    ClientTop       =   330
  9.    ClientWidth     =   4680
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   2625
  14.    ScaleWidth      =   4680
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin VB.CommandButton cmdDone 
  17.       Caption         =   "Do&ne"
  18.       Height          =   375
  19.       Left            =   3240
  20.       TabIndex        =   13
  21.       TabStop         =   0   'False
  22.       Top             =   2160
  23.       Width           =   1215
  24.    End
  25.    Begin VB.CommandButton cmdDelete 
  26.       Caption         =   "&Delete"
  27.       Height          =   375
  28.       Left            =   1680
  29.       TabIndex        =   12
  30.       TabStop         =   0   'False
  31.       Top             =   2160
  32.       Width           =   1215
  33.    End
  34.    Begin VB.CommandButton cmdEdit 
  35.       Caption         =   "&Edit"
  36.       Height          =   375
  37.       Left            =   120
  38.       TabIndex        =   11
  39.       TabStop         =   0   'False
  40.       Top             =   2160
  41.       Width           =   1215
  42.    End
  43.    Begin VB.CommandButton cmdCancel 
  44.       Caption         =   "&Cancel"
  45.       Height          =   375
  46.       Left            =   3240
  47.       TabIndex        =   10
  48.       TabStop         =   0   'False
  49.       Top             =   1680
  50.       Width           =   1215
  51.    End
  52.    Begin VB.CommandButton cmdSave 
  53.       Caption         =   "&Save"
  54.       Height          =   375
  55.       Left            =   1680
  56.       TabIndex        =   9
  57.       TabStop         =   0   'False
  58.       Top             =   1680
  59.       Width           =   1215
  60.    End
  61.    Begin VB.CommandButton cmdAddNew 
  62.       Caption         =   "&Add New"
  63.       Height          =   375
  64.       Left            =   120
  65.       TabIndex        =   8
  66.       TabStop         =   0   'False
  67.       Top             =   1680
  68.       Width           =   1215
  69.    End
  70.    Begin VB.CommandButton cmdNext 
  71.       Caption         =   "Next =>"
  72.       Height          =   255
  73.       Left            =   2520
  74.       TabIndex        =   7
  75.       TabStop         =   0   'False
  76.       Top             =   1320
  77.       Width           =   1215
  78.    End
  79.    Begin VB.CommandButton cmdPrevious 
  80.       Caption         =   "<= Previous"
  81.       Height          =   255
  82.       Left            =   1080
  83.       TabIndex        =   6
  84.       TabStop         =   0   'False
  85.       Top             =   1320
  86.       Width           =   1215
  87.    End
  88.    Begin VB.TextBox txtYearBorn 
  89.       DataField       =   "Year Born"
  90.       DataSource      =   "datAuthors"
  91.       Height          =   285
  92.       Left            =   1200
  93.       Locked          =   -1  'True
  94.       MaxLength       =   4
  95.       TabIndex        =   2
  96.       Text            =   "Text"
  97.       Top             =   840
  98.       Width           =   1215
  99.    End
  100.    Begin VB.TextBox txtAuthor 
  101.       DataField       =   "Author"
  102.       DataSource      =   "datAuthors"
  103.       Height          =   285
  104.       Left            =   1200
  105.       Locked          =   -1  'True
  106.       TabIndex        =   1
  107.       Text            =   "Text2"
  108.       Top             =   480
  109.       Width           =   3375
  110.    End
  111.    Begin VB.TextBox txtAuthorID 
  112.       DataField       =   "Au_ID"
  113.       DataSource      =   "datAuthors"
  114.       Height          =   285
  115.       Left            =   1200
  116.       Locked          =   -1  'True
  117.       TabIndex        =   3
  118.       TabStop         =   0   'False
  119.       Text            =   "Text1"
  120.       Top             =   120
  121.       Width           =   1215
  122.    End
  123.    Begin MSAdodcLib.Adodc datAuthors 
  124.       Height          =   330
  125.       Left            =   2520
  126.       Top             =   120
  127.       Visible         =   0   'False
  128.       Width           =   2055
  129.       _ExtentX        =   3625
  130.       _ExtentY        =   582
  131.       ConnectMode     =   0
  132.       CursorLocation  =   3
  133.       IsolationLevel  =   -1
  134.       ConnectionTimeout=   15
  135.       CommandTimeout  =   30
  136.       CursorType      =   3
  137.       LockType        =   3
  138.       CommandType     =   1
  139.       CursorOptions   =   0
  140.       CacheSize       =   50
  141.       MaxRecords      =   0
  142.       BOFAction       =   0
  143.       EOFAction       =   0
  144.       ConnectStringType=   1
  145.       Appearance      =   1
  146.       BackColor       =   -2147483643
  147.       ForeColor       =   -2147483640
  148.       Orientation     =   0
  149.       Enabled         =   -1
  150.       Connect         =   "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\VBDB\Working\Biblio.mdb"
  151.       OLEDBString     =   "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\VBDB\Working\Biblio.mdb"
  152.       OLEDBFile       =   ""
  153.       DataSourceName  =   ""
  154.       OtherAttributes =   ""
  155.       UserName        =   ""
  156.       Password        =   ""
  157.       RecordSource    =   "SELECT * FROM Authors ORDER BY Author"
  158.       Caption         =   "Adodc1"
  159.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  160.          Name            =   "MS Sans Serif"
  161.          Size            =   8.25
  162.          Charset         =   0
  163.          Weight          =   400
  164.          Underline       =   0   'False
  165.          Italic          =   0   'False
  166.          Strikethrough   =   0   'False
  167.       EndProperty
  168.       _Version        =   393216
  169.    End
  170.    Begin VB.Label Label3 
  171.       Caption         =   "Year Born"
  172.       Height          =   255
  173.       Left            =   120
  174.       TabIndex        =   5
  175.       Top             =   840
  176.       Width           =   1215
  177.    End
  178.    Begin VB.Label Label2 
  179.       Caption         =   "Author Name"
  180.       Height          =   255
  181.       Left            =   120
  182.       TabIndex        =   4
  183.       Top             =   480
  184.       Width           =   1215
  185.    End
  186.    Begin VB.Label Label1 
  187.       Caption         =   "Author ID"
  188.       Height          =   255
  189.       Left            =   120
  190.       TabIndex        =   0
  191.       Top             =   120
  192.       Width           =   1215
  193.    End
  194. Attribute VB_Name = "frmAuthors"
  195. Attribute VB_GlobalNameSpace = False
  196. Attribute VB_Creatable = False
  197. Attribute VB_PredeclaredId = True
  198. Attribute VB_Exposed = False
  199. Option Explicit
  200. Private Sub ValidateData(AllOK As Boolean)
  201. Dim Message As String
  202. Dim InputYear As Integer, CurrentYear As Integer
  203. AllOK = True
  204. Message = ""
  205. 'Check for name
  206. If Len(txtAuthor.Text) = 0 Then
  207.   Message = "You must enter an Author Name." + vbCrLf
  208.   txtAuthor.SetFocus
  209.   AllOK = False
  210. End If
  211. 'Check length and range on Year Born
  212. InputYear = Val(txtYearBorn.Text)
  213. CurrentYear = Val(Format(Now, "yyyy"))
  214. If Len(txtYearBorn.Text) <> 0 Then
  215.   If InputYear > CurrentYear Or InputYear < CurrentYear - 150 Then
  216.     Message = Message + "Year Born must be between" & Str(CurrentYear - 150) & " and" & Str(CurrentYear) & "."
  217.     txtYearBorn.SetFocus
  218.     AllOK = False
  219.   End If
  220. End If
  221. If Not (AllOK) Then
  222.   MsgBox Message, vbOKOnly + vbInformation, "Validation Error"
  223. End If
  224. End Sub
  225. Private Sub cmdAddNew_Click()
  226. On Error GoTo HandleErrors
  227. Call SetState("Add")
  228. Exit Sub
  229. HandleErrors:
  230. Select Case MsgBox(Err.Description, vbCritical + vbAbortRetryIgnore, "Error Number" + Str(Err.Number) + " in " + Err.Source)
  231. Case vbAbort
  232.   Exit Sub
  233. Case vbRetry
  234.   Resume
  235. Case vbIgnore
  236.   Resume Next
  237. End Select
  238. End Sub
  239. Private Sub cmdCancel_Click()
  240. Call SetState("View")
  241. End Sub
  242. Private Sub cmdDelete_Click()
  243. Dim Response As Integer
  244. On Error GoTo HandleErrors
  245. Response = MsgBox("Are you sure you want to delete this record?", vbYesNo + vbQuestion + vbDefaultButton2, "Delete")
  246. If Response = vbNo Then
  247.   Exit Sub
  248. End If
  249. Exit Sub
  250. HandleErrors:
  251. Select Case MsgBox(Err.Description, vbCritical + vbAbortRetryIgnore, "Error Number" + Str(Err.Number) + " in " + Err.Source)
  252. Case vbAbort
  253.   Exit Sub
  254. Case vbRetry
  255.   Resume
  256. Case vbIgnore
  257.   Resume Next
  258. End Select
  259. End Sub
  260. Private Sub cmdEdit_Click()
  261. Call SetState("Edit")
  262. End Sub
  263. Private Sub cmdNext_Click()
  264. datAuthors.Recordset.MoveNext
  265. If datAuthors.Recordset.EOF Then
  266.   Beep
  267.   datAuthors.Recordset.MoveLast
  268. End If
  269. End Sub
  270. Private Sub cmdPrevious_Click()
  271. datAuthors.Recordset.MovePrevious
  272. If datAuthors.Recordset.BOF Then
  273.   Beep
  274.   datAuthors.Recordset.MoveFirst
  275. End If
  276. End Sub
  277. Private Sub cmdSave_Click()
  278. Dim Valid As Boolean
  279. Call ValidateData(Valid)
  280. If Not (Valid) Then Exit Sub
  281. On Error GoTo HandleErrors
  282. MsgBox "Record saved.", vbOKOnly + vbInformation, "Save"
  283. Call SetState("View")
  284. Exit Sub
  285. HandleErrors:
  286. Select Case MsgBox(Err.Description, vbCritical + vbAbortRetryIgnore, "Error Number" + Str(Err.Number) + " in " + Err.Source)
  287. Case vbAbort
  288.   Exit Sub
  289. Case vbRetry
  290.   Resume
  291. Case vbIgnore
  292.   Resume Next
  293. End Select
  294. End Sub
  295. Private Sub SetState(AppState As String)
  296. Select Case AppState
  297. Case "View"
  298.   txtAuthorID.BackColor = vbWhite
  299.   txtAuthor.Locked = True
  300.   txtYearBorn.Locked = True
  301.   cmdPrevious.Enabled = True
  302.   cmdNext.Enabled = True
  303.   cmdAddNew.Enabled = True
  304.   cmdSave.Enabled = False
  305.   cmdCancel.Enabled = False
  306.   cmdEdit.Enabled = True
  307.   cmdDelete.Enabled = True
  308.   cmdDone.Enabled = True
  309.   txtAuthor.SetFocus
  310. Case "Add", "Edit"
  311.   txtAuthorID.BackColor = vbRed
  312.   txtAuthor.Locked = False
  313.   txtYearBorn.Locked = False
  314.   cmdPrevious.Enabled = False
  315.   cmdNext.Enabled = False
  316.   cmdAddNew.Enabled = False
  317.   cmdSave.Enabled = True
  318.   cmdCancel.Enabled = True
  319.   cmdEdit.Enabled = False
  320.   cmdDelete.Enabled = False
  321.   cmdDone.Enabled = False
  322.   txtAuthor.SetFocus
  323. End Select
  324. End Sub
  325. Private Sub Form_Activate()
  326. Call SetState("View")
  327. End Sub
  328. Private Sub txtAuthor_KeyPress(KeyAscii As Integer)
  329. If KeyAscii = vbKeyReturn Then
  330.   txtYearBorn.SetFocus
  331.   Exit Sub
  332. End If
  333. End Sub
  334. Private Sub txtYearBorn_KeyPress(KeyAscii As Integer)
  335. If KeyAscii = vbKeyReturn Then
  336.   txtAuthor.SetFocus
  337.   Exit Sub
  338. End If
  339. If (KeyAscii >= Asc("0") And KeyAscii <= Asc("9")) Or KeyAscii = vbKeyBack Then
  340.   Exit Sub
  341.   Beep
  342.   KeyAscii = 0
  343. End If
  344. End Sub
  345.